import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// import eslintPlugin from 'vite-plugin-eslint';

// https://vite.dev/config/
export default defineConfig({
  // base: '/dapp/',
  assetsInclude: [
    "**/*.png, **/*.jpg, **/*.jpeg, **/*.gif, **/*.svg, **/*.ico, **/*.webp",
  ],
  plugins: [
    react(),
    // eslintPlugin()
  ],
  resolve: {
    alias: {
      "@": "/src",
    },
    extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  },
  css: {
    modules: {
      hashPrefix: "prefix",
      generateScopedName: "[name]__[local]___[hash:base64:5]",
    },
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  build: {
    rollupOptions: {
      output: {
        entryFileNames: "js/[name]-[hash].js",
        chunkFileNames: "js/[name]-[hash].js",
        assetFileNames: (assetInfo) => {
          // 设置不同类型文件的输出路径及命名规则
          if (
            assetInfo.type === "asset" &&
            /\.(jpe?g|png|gif|svg)$/i.test(assetInfo.name as string)
          ) {
            return "img/[name].[hash].[ext]"; // 图像文件输出路径及命名规则
          }
          if (
            assetInfo.type === "asset" &&
            /\.(ttf|woff|woff2|eot)$/i.test(assetInfo.name as string)
          ) {
            return "fonts/[name].[hash].[ext]"; // 字体文件输出路径及命名规则
          }
          return "[ext]/[name]-[hash].[ext]"; // 其他资源文件输出路径及命名规则
        },
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        },
      },
    },
  },
  server: {
    proxy: {
      "/dapp": {
        target: "http://splitadmin.richknown.com/dapp",
      },
    },
  },
});
